package com.xyy.saas.payment.callback;

import com.alibaba.fastjson.JSON;
import com.xyy.saas.payment.constants.RocketMqTopic;
import com.xyy.saas.payment.mq.MqProducer;
import com.xyy.saas.payment.pojo.dto.CallbackMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wangtianqi
 * @date 2019/11/25 19:27
 */
@Component
public class CallbackRunner {

    @Autowired
    private MqProducer mqProducer;

    /**
     * 执行回调
     */
    public void callback(String tradeNo, String type, Integer amount, Integer fee, Long successTime, String callback) {
        callback(tradeNo, type, amount, fee, successTime, callback, null, null, null, null);
    }
    public void callback(String tradeNo, String type, Integer amount, Integer fee, Long successTime, String callback, String channel) {
        callback(tradeNo, type, amount, fee, successTime, callback, channel, null, null, null);
    }
    public void callback(String tradeNo, String type, Integer amount, Integer fee, Long successTime, String callback, String channel, String msg) {
        callback(tradeNo, type, amount, fee, successTime, callback, channel, msg, null, null);
    }
    public void callback(String tradeNo, String type, Integer amount, Integer fee, Long successTime, String callback, String channel, String msg, String extend) {
        callback(tradeNo, type, amount, fee, successTime, callback, channel, msg, extend, null);
    }
    public void callback(String tradeNo, String type, Integer amount, Integer fee, Long successTime, String callback, String channel, String msg, String extend, String businessOrderNo) {
        CallbackMsg callbackMsg = new CallbackMsg(tradeNo, type, amount, fee, successTime, callback, channel, msg, extend, businessOrderNo);
        mqProducer.syncSendMsg(RocketMqTopic.TOPIC_CALLBACK, JSON.toJSONString(callbackMsg));
    }

    /**
     * 发送消息
     * @param callbackMsg
     */
    public void callback(CallbackMsg callbackMsg) {
        mqProducer.syncSendMsg(RocketMqTopic.TOPIC_CALLBACK, JSON.toJSONString(callbackMsg));
    }

    /**
     * 根据Topc发送消息
     * @param topic
     * @param callbackMsg
     */
    public void callback(String topic, CallbackMsg callbackMsg) {
        mqProducer.syncSendMsg(topic, JSON.toJSONString(callbackMsg));
    }

    public void syncSendMsg(String topic, Object domain){
        mqProducer.syncSendMsg(topic, JSON.toJSONString(domain));
    }


}
